package com.baozun.houji.viewmodel

import androidx.lifecycle.MutableLiveData
import com.baozhun.mall.common.model.bean.ContinueBuyStatusBean
import com.baozhun.mall.common.network.mCommonApiService
import com.baozhun.mall.common.util.CacheUtil
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request
import kotlin.random.Random

class MainViewModel : BaseViewModel() {

    var mMsgCount = MutableLiveData<Int?>()
    var mClearMsgSuccess = MutableLiveData<Boolean?>()

    /**
     * 获取消息数量
     */
    fun getMsgCount() {
        if (!CacheUtil.isLogin()) return
        request({ mCommonApiService.getMsgCount() }, {
            mMsgCount.value = it
        })
    }

    /**
     * 消息已读
     */
    fun readMsg() {
        if (!CacheUtil.isLogin() || (mMsgCount.value ?: 0) <= 0) return
        request({ mCommonApiService.readMsg() }, {
            mClearMsgSuccess.value = true
        }, isShowDialog = false, showErrorMsg = false)
    }

    /**
     * 获取app配置信息
     */
    fun getAppConfig(onResponseSuccessBack: () -> Unit) {
        request({ mCommonApiService.getAppConfig() }, {
            CacheUtil.setAppConfig(it)
            onResponseSuccessBack.invoke()
        }, {
            onResponseSuccessBack.invoke()
        })
    }

}